package com.banmao.rabbitmq.c3_topic;

import com.banmao.rabbitmq.utils.RabbitConstant;
import com.banmao.rabbitmq.utils.RabbitUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import lombok.extern.slf4j.Slf4j;

import java.util.LinkedHashMap;
import java.util.Map;

@Slf4j
public class WeatherBureau {

    public static void main(String[] args) throws Exception {
        LinkedHashMap<String, String> areas = new LinkedHashMap<>() {
            {
                put("china.guangdong.guangzhou.20991011", "中国广东广州20991011天气");
                put("china.hebei.shijiazhuang.20991011", "中国河北石家庄20991011天气");
                put("china.guangdong.guangzhou.20991012", "中国广东广州20991012天气");
                put("china.hebei.shijiazhuang.20991012", "中国河北石家庄20991012天气");
            }
        };

        Connection connection = RabbitUtil.getConnection();
        Channel channel = connection.createChannel();

        for (Map.Entry<String, String> entry : areas.entrySet()) {
            String key = entry.getKey();
            String value = entry.getValue();
            // 使用路由模式时，则指定 routingKey
            channel.basicPublish(RabbitConstant.EXCHANGE_WATHER_TOPIC, key, null, value.getBytes());
        }

        channel.close();
        connection.close();
    }
}
